/**
 * <p>Copyright:Copyright(c) 2019</p>
 * <p>Company:Professional</p>
 * <p>Package:org.cesgroup.course.sample.hype</p>
 * <p>File:Config.java</p>
 * <p>类更新历史信息</p>
 * @todo chanlong(陈龙) 创建于 Sep 16, 2019 1:31:48 PM
 */
package org.cesgroup.course.sample.hype;

import java.util.Set;

import org.cesgroup.course.interceptor.Interceptor;
import org.cesgroup.course.interceptor.ProxyChain;

import cn.hutool.core.util.ClassUtil;

/**
 * <p>描述: </p>
 * <p>Company: Professional</p>
 * @author chanlong(陈龙)
 * @date Sep 16, 2019 1:31:48 PM
 * @version 1.0.2019
 */
public class Config {
	
	private final static ProxyChain<Handler> proxyChain = new ProxyChain<>();
	
	// 初始化责任链，通过报扫描的方式，扫描并加载所有实现了“Interceptor”接口的实现类，并添加到“ProxyChain”中
	public static void init() throws Throwable {
		Set<Class<?>> classes = ClassUtil.scanPackageBySuper("org.cesgroup.course.sample.hype", Interceptor.class);
		for (Class<?> clazz : classes) {
			Interceptor interceptor = (Interceptor)clazz.newInstance();
			proxyChain.addInterceptor(interceptor);
		}
	}
	
	// 获取并启动责任链
	public static Handler chain() {
		return proxyChain.all(new DefaultHandler());
	}
}
